<template>
    <h3>理财信息添加</h3>
    <table>
        <tr>
            <td>项目名称</td>
            <td><input type="text" v-model="F_Name"></td>
        </tr>
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="F_Year"></td>
        </tr>
        <tr>
            <td>月收益</td>
            <td><input type="text" v-model="F_Month"></td>
        </tr>
        <tr>
            <td>最低金额</td>
            <td><input type="text" v-model="MinMoney"></td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
                <input type="radio" v-model="Level" checked>低风险
                <input type="radio" v-model="Level">中风险
                <input type="radio" v-model="Level">高风险
            </td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                <select v-model="I_Id">
                    <option v-for="item in str" :key="item.I_Id" :value="item.I_Id"></option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2"><button @click="Add">添加</button></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';

const F_Name = ref("");
const F_Year = ref();
const F_Month = ref();
const MinMoney = ref();
const Level = ref("");
const I_Id = ref();

const str = ref([
    {
        I_Id: 0,
        I_Inverest: ""
    }
])
//绑定下拉 钩子函数
onMounted(() => {
    axios.get('http://localhost:56486/api/Financing/BindInverest', {
        params: {
            I_Id: I_Id
        }
    })
        .then(res => {
            str.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
})

const Add = () => {
    if (!F_Name.value) {
        alert("理财名称不能为空")
        return;
    }
    if (!F_Year.value) {
        alert("年收益不能为空")
        return;
    }
    if (!F_Month.value) {
        alert("月收益不能为空")
        return;
    }
    if (!MinMoney.value) {
        alert("最低金额不能为空")
        return;
    }
    axios.post('http://localhost:56486/api/Financing/AddFinancing')
        .then(res => {
            if (res.data > 0) {
                alert("添加成功")
                Jump();
            }
            else {
                alert("添加失败")
                return;
            }
        })
        .catch(error => {
            console.log(error);
        })
}
const router = useRouter();
const Jump = () => {
    router.push('ShowFinancing')
}
</script>